import dom, { ajax, domg } from "../js/init.js";
import { obj } from "../js/index.js";
import { classche } from "../js/navigation/eventhandle.js";
import { initarticle } from "../js/content/article/aritcle.js";
import { initcomment } from "../js/content/comment/comment.js";
import { initCreatedShuoshuo } from "../js/content/shuoshuo/shuoshuo.js";
import { initMyArticle } from "../js/content/myarticle/myaricle.js";
import { initAbout } from "../js/content/about/about.js";
import { initandmi } from "../js/content/andmi/andmi.js";

window.onhashchange = function () {
  const hash = location.hash.slice(1);
  if (hash == "/index") {
    initarticle();
    (dom.herder.findtitleipt as any).value = "";
    classche(dom.index.index);
  }
  if (hash == "/comment") {
    initcomment();
    classche(dom.index.comment);
  }
  if (hash == "/shuoshuo") {
    if (!obj.islogin) {
      alert("当前未登录即将跳转到关于");
      initAbout();
      history.replaceState(null, "#/About", "/About");
      return classche(dom.index.about);
    }
    initCreatedShuoshuo();
    classche(dom.index.shuoshuo);
  }
  if (hash.includes("/MyArticle")) {
    if (localStorage.getItem("article")) {
      dom.index.article.style.display = "block";
    }
    initMyArticle();
    classche(dom.index.article);
    if (hash.includes("C")) {
      setTimeout(() => {
        location.href = location.href;
      }, 100);
    }
  }
  if (hash == "/About") {
    initAbout();
    classche(dom.index.about);
  }
  if (hash == "/Andmi") {
    if (!obj.isAndmi) {
      alert("当前用户非管理局即将重定向到关于");
      classche(dom.index.about);
      history.replaceState(null, "#/About", "/About");
      return initAbout();
    }
    initandmi();
    classche(dom.index.andmi);
  }
  if (hash === "/find") {
    classche(dom.index.index);
  }
};
